/*
https://leetcode.cn/problems/minimum-limit-of-balls-in-a-bag/?envType=problem-list-v2&envId=binary-search
袋子里最少数目的球
二分搜索
*/
class Solution {
    
public:
    bool find(int x, int maxOperations, vector<int>& nums)
    {
        int k = 0;
        for(int i = 0;i < nums.size();i++)
        {
            if (nums[i] > x)
            {
                k += int((nums[i] - 1)/x);
            }
        }
        return k > maxOperations?true:false;
    }
    int minimumSize(vector<int>& nums, int maxOperations) {
        int m = 0;
        int len = nums.size();
        sort(nums.begin(),nums.end());
        for(int i = 0;i < len;i++)
        {
            m = max(m, nums[i]);
        }
        int left = 1;
        int right = m;
        while(left < right)
        {
            int mid = (left+right)>>1;
            cout<<left<<right<<mid<<endl;
            if(find(mid, maxOperations, nums)) left = mid + 1;
            else right = mid;
        }
        return right;

    }
};